-- Parameters local outletValve = 2 -- vent to outlet valve, FIO number local inletValve = 0 -- pressurize system valve, FIO number local pressureTransducer = 0 -- Pressure transducer AIN number LJ.IntervalConfig(0, 1000) -- Control loop period in ms -- Local variables for speed local checkInterval = LJ.CheckInterval local mbR = MB.R local mbW = MB.W local RPM = 400 local maxRPM = 1000 local desiredPumpPSI = 120 local currentPumpPSI = 0 mbW(46000, 3, 0) -- clear user RAM mbW(46180, 0, 14) -- reset setpoint mbW(48005, 0, 1) --ensure analog system is powered on --SPI Params mbW(5000, 0, 4) --CS (FIO4) mbW(5001, 0, 5) --CLK (FIO5) mbW(5002, 0, 6) --MISO (FIO6) mbW(5003, 0, 7) --MOSI (FIO7) mbW(5004, 0, 1) --Mode mbW(5005, 0, 65500) --Speed mbW(5006, 0, 0) --Options, disable CS mbW(5009, 0, 1) --Num Bytes to Tx/Rx print("Initialized") --Step 1: Ensure 4-thruster equivalent flow restriction is installed --Step 2: Load and Prime the system with one of the viscosity analog fluids --Step 3: Open Inlet and Outlet Valves. --LJ.DIO_S_W(outletValve,0) -- Changes outlet valve to output low --LJ.DIO_D_W(outletValve,1) -- Turn on output valve -- --LJ.DIO_S_W(inletValve,0) -- Changes inlet valve to output low --LJ.DIO_D_W(inletValve,1) -- Turn on inlet valve --Step 4: Sweep from 500 ROM to max motor power, accelerating at 100RPM/sec. print("SPI Test, using simple MB") LJ.IntervalConfig(4, 500) local iTest = 0 while true do if LJ.CheckInterval(4) then mbW(5009, 0, 1) -- One byte to transfer mbW(5010, 0, iTest * 256) -- Incrementing value to transfer mbW(5007, 0, 1) -- Start the SPI transaction RxValue = mbR(5050, 0) / 256 print(RxValue) iTest = iTest + 1 -- Increment... if(iTest >= 8) then break end end end print("SPI Test, using array MB") local iTest = 0 local TxData = {} while true do if LJ.CheckInterval(4) then TxData[1] = iTest TxData[2] = iTest+1 TxData[3] = iTest+2 TxData[4] = iTest+3 mbW(5009, 0, 4) -- num bytes to transfer MB.WA(5010, 99, 4, TxData) -- Incrementing value to transfer mbW(5007, 0, 1) -- Start the SPI transaction RxValues = MB.RA(5050, 99, 4) print(RxValues[1], RxValues[2], RxValues[3], RxValues[4]) iTest = iTest + 1 -- Increment... if(iTest >= 32) then break end end end while true do if LJ.CheckInterval(0) then if RPM < maxRPM then RPM = RPM + 100 print ("RPM is : ", RPM) else print("Max RPM") break end end end --Step 5: Control Output Pressure to flight level and run pump until steady state temp is reached. local testData = {{0x01}} local dataSelect = 1-- 1 or 2 for each dataset, change this for different data sets LJ.IntervalConfig(0, 100) --Configure Interval, in millis local checkInterval=LJ.CheckInterval while true do if checkInterval(0) then local pressure = mbR(pressureTransducer * 2, 3) * 29.6209 - 50 -- Read AIN0, convert to PSIA print(pressure) local testLen = table.getn(testData[dataSelect]) MB.W(5009, 0, testLen)--load the number of bytes MB.WA(5010, 99, testLen, testData[dataSelect])--load data into DATA_TX MB.W(5007, 0, 1)--SPI_GO local rxData = MB.RA(5050, 99, testLen)--read data from DATA_RX --Compare the data local pass = 1 for i=1,testLen do print(testData[dataSelect][i]) if(testData[dataSelect][i] ~= rxData[i]) then print(string.format("0x%x (tx) does not match 0x%x (rx)", testData[dataSelect][i], rxData[i]))--Show data recieved pass = 0 end end if(pass == 1) then print("Data recieved") else print("----") end end end --Step 6: Repeat with other propellant viscosity analog fluid.